﻿using System;
using NUnit.Framework;
using PhantomChainsAnalyser.Model;

namespace TestPhantomChainsAnalyser
{
    [TestFixture]
    public class TestSampling
    {
        [Test]
        public void TestVolume()
        {
            Sampling sample = new Sampling();
            sample.AddValue(1);
            sample.AddValue(2);
            sample.AddValue(4);
            sample.AddValue(-10);
            Assert.AreEqual(4,sample.GetVolume());
        }

        [Test]
        public void TestGetValue()
        {
            Sampling sample = new Sampling();
            sample.AddValue(1);
            sample.AddValue(2);
            sample.AddValue(4);
            sample.AddValue(-10);
            Assert.AreEqual(-10,sample[3]);
            Assert.AreEqual(1,sample[0]);
            Assert.AreEqual(2,sample.GetValue(1));
            Assert.AreEqual(4, sample.GetValue(2));
        }

        [Test]
        public void TestMinMax()
        {
            Sampling sample = new Sampling();
            sample.AddValue(1);
            sample.AddValue(2);
            sample.AddValue(4);
            sample.AddValue(-10);
            Assert.AreEqual(-10,sample.Min());
            Assert.AreEqual(4,sample.Max());
        }

        [Test]
        public void TestRanged()
        {
            Sampling sample = new Sampling();
            sample.AddValue(1);
            sample.AddValue(4);
            sample.AddValue(2);
            sample.AddValue(-10);
            Sampling ranged = sample.RangedSampling();
            Assert.AreEqual(-10,ranged[0]);
            Assert.AreEqual(1, ranged[1]);
            Assert.AreEqual(2, ranged[2]);
            Assert.AreEqual(4, ranged[3]);
            Assert.AreEqual(4,ranged.GetVolume());
        }

        [Test]
        public void TestAverageValue()
        {
            Sampling sample = new Sampling();
            sample.AddValue(1);
            sample.AddValue(4);
            sample.AddValue(2);
            sample.AddValue(-10);
            Assert.AreEqual(-0.75,sample.AvеrageValue());
        }

        [Test]
        public void TestRangedSetValue()
        {
            Sampling sample = new Sampling();
            sample.AddValue(1);
            sample.AddValue(4);
            sample.AddValue(2);
            sample.AddValue(-10);
            sample.SetValue(1,6);
            sample[2] = 3;
            Sampling ranged = sample.RangedSampling();
            Assert.AreEqual(-10, ranged[0]);
            Assert.AreEqual(1, ranged[1]);
            Assert.AreEqual(3, ranged[2]);
            Assert.AreEqual(6, ranged[3]);
            Assert.AreEqual(4, ranged.GetVolume());
        }

        [Test]
        public void TestDispersion()
        {
            Sampling sample = new Sampling();
            sample.AddValue(1);
            sample.AddValue(4);
            sample.AddValue(2);
            sample.AddValue(-10);
            Assert.AreEqual(29.6875, sample.Dispersion());
        }

        [Test]
        public void TestMeanSquareDeviation()
        {
            Sampling sample = new Sampling();
            sample.AddValue(1);
            sample.AddValue(4);
            sample.AddValue(2);
            sample.AddValue(-10);
            Assert.AreEqual(Math.Sqrt(29.6875), sample.MeanSquareDeviation());
        }
    }
}
